package com.wangzemin.leetcoded.num278;


public class Solution extends VersionControl {
    public int firstBadVersion(int n) {
        if (n <= 0) {
            return -1;
        }

        int minBadVersion = -1;
        int left = 1;
        int right = n;
        while (left <= right) {
            int mid = left + (right-left) / 2;
            if (isBadVersion(mid)) {
                minBadVersion = mid;
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return minBadVersion;
    }
}